const app = getApp()
Page({
  data: {
    tabbar_index:0,
    islogin:false,
    videoid:0,
    changeuser:0
  },
  changeuser:function(){
     this.setData({
        changeuser:1
     })
  },
  tabnav:function(e){
       this.setData({
        videoList:e.detail.data
      })
  },
  get_type:function(e){
  if(e.detail.now_index!==0&&e.detail.now_index!==3){
    wx.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#000000',
      animation: {
        duration: 400,
        timingFunc: 'easeIn'
      }
    })
  }else{
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#ffffff',
      animation: {
        duration: 400,
        timingFunc: 'easeIn'
      }
    })
  }
   this.setData({
      tabbar_index:e.detail.now_index,
      tabbar_type:e.detail.tabbar_type,
      tabbar_title:e.detail.tabbar_title,
      titleShow:e.detail.titleShow,
      pageid:e.detail.pageid,
      globalColor:e.detail.globalColor
    })
   },
   get_data:function(){
    var that=this
    if(typeof(that.data.videoid)!='undefined')
    {
      wx.request({
        url: app.globalData.siteroot,
        data: { 
          do:'Video_getVideo',
          id:that.data.videoid,
          is_next:0,
          is_release:0
        },
        success: function(res) { 
          wx.setStorageSync('site_config',res.data.site_config);
          var videoList=res.data.data
          for(var s=1;s<videoList.length; s++){
            var realurl=videoList[s].realurl
             wx.request({
              url: app.globalData.siteroot,
              data: {
                do:'Video_realUrl',
                type:videoList[s].type,
                url:videoList[s].url,
                vid:videoList[s].id
              },
              success: function(res) {
                realurl=res.data.data
              }
            })
            videoList[s].realurl=realurl
        }
          that.setData({
            videoList:videoList
          })
        }
      })
    }else
    {
      wx.request({
        url: app.globalData.siteroot,
        data: {
          do:'Video_getVideo',
        },
        success: function(res) {
            wx.setStorageSync('site_config',res.data.site_config);
            that.setData({
             videoList:res.data.data
          })
        }
      })
    }
   },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
    if(typeof(options.id)!='undefined')
    {
      that.setData({
        videoid:options.id
      })
      that.get_data();
    }else
    {
      that.get_data();
    }
    if(options.tabbar_index!='')
    {
      this.setData({
        tabbar_index:options.tabbar_index,
        tabbar_type:options.tabbar_type,
        tabbar_title:options.tabbar_title
      })
    }

    if(wx.getStorageSync('userinfo')=='')
    {
            this.setData({
               islogin:true,
               pagetype:'login'
            })
    }
    else{
         var user_info=wx.getStorageSync('userinfo');
         if(user_info.phone == null ||user_info.phone=='null')
         {
          this.setData({
              islogin:true,
              pagetype:'phone'
           })
         }
    }
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        that.setData({
          latitude: res.latitude,
          longitude: res.longitude,
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
           this.setData({
            globalColor:app.globalData.globalColor
           })
       if(typeof(wx.getStorageSync('authInfo'))!='undefined'){
            this.setData({
            authInfo:wx.getStorageSync('authInfo')
          })
        }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  sharefriend:function(e){
    var sharepath='/yb_shopv2/entry/video-market/index';
    if(typeof(e.detail.id)!='undefined'){
      sharepath='/yb_shopv2/entry/video-market/index?id='+e.detail.id;
    }
    this.setData({
      sharetitle:e.detail.title,
      sharecover:e.detail.cover,
      shareid:e.detail.id,
      sharepath:sharepath
    })
  },
  changeshare:function(e){
    this.setData({
      sharetitle:e.detail,
      sharecover:''
    })
  },
  onShareAppMessage: function (e) {
    return console.log(e, "页面内按钮分享0"), {
      title:typeof(this.data.sharetitle)!='undefined'?this.data.sharetitle:'',
      imageUrl:typeof(this.data.sharecover)!='undefined'?this.data.sharecover:'',
      path:typeof(this.data.sharepath)!='undefined'?this.data.sharepath:'/yb_shopv2/entry/video-market/index'
    };
  }
})